#include "LJNAudioPlayer.h"
#include <iostream>
#include <thread>
#include <string>
#include <chrono>
#include <cmath>

int main(int argc, char *argv[]) {
    if (argc < 2) {
        std::cerr << "Usage: audioPath , patch" << std::endl;
        return 1;
    }

    std::string filePath = argv[1];
    float patch = argc > 2 ? std::stof(argv[2]) : 0.0f;

    LJNAudio::AudioPlayer player;
    if (!player.Init(filePath)) {
        std::cerr << "Failed to initialize audio player." << std::endl;
        return 1;
    }
    player.Play();
    float pitch_value = std::pow(2.0, patch / 12.0);
    std::cout << "###### set pitch " << pitch_value << std::endl;
    bool result = player.SetPitch(pitch_value);
    int32_t durationInMs = player.GetDurationInMs();
    if (!result) {
        std::cerr << "Failed to set pitch." << std::endl;
        // return 1;
    }
    std::cout << "###### start play" << std::endl;
    // player.Play();
    // std::this_thread::sleep_for(std::chrono::seconds(5));
    // std::cout << "###### seek to 10 seconds" << std::endl;
    // if (!player.SeekTo(10000)) {
    //     std::cerr << "Failed to seek to 10 seconds." << std::endl;
    //     return 1;
    // }
    // std::this_thread::sleep_for(std::chrono::seconds(10));
    // std::cout << "###### pause" << std::endl;
    // player.Pause();
    // std::this_thread::sleep_for(std::chrono::seconds(1));
    // std::cout << "###### play" << std::endl;
    // player.Pause();
    std::this_thread::sleep_for(std::chrono::milliseconds(durationInMs));
    std::cout << "###### stop" << std::endl;
    player.Stop();
    player.Destroy();
    return 0;
}